package greetings

import (
	"fmt"
	"sync"
)

func CreateMapDemo() map[string]string {
	messages := make(map[string]string)
	messages["1"] = "121"
	messages["2"] = "122"
	messages["3"] = "123"
	messages["4"] = "124"

	v1 := messages["1"]
	fmt.Println("v1 is :", v1)
	return messages
}

func AnyParam() {

	// 空接口作为map值
	var studentInfo = make(map[string]interface{})
	studentInfo["name"] = "李白"
	studentInfo["age"] = 18
	studentInfo["married"] = false
	fmt.Println(studentInfo)
}

// SyncMapDemo 多线程安全的map
func SyncMapDemo() {

	m := sync.Map{}
	m.Store("a", 1)
	m.Store("b", 2)
	m.Store("c", 3)

	v, ok := m.Load("b")
	if ok {
		b := v.(int)
		fmt.Println("map is :", b)
	}
}
